define(['jquery', 'bootstrap', 'form', 'table'], function ($, undefined, Form, Table) {
    var Controller = {
        index: function () {
            var table = $("#table");
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: '/auth/admin/index' + location.search,
                    add_url: '/auth/admin/add',
                    edit_url: '/auth/admin/edit',
                    del_url: '/auth/admin/del',
                    table: 'admin',
                }
            });

            $(table).bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    {checkbox: true,}, {field: 'id', title: 'ID',},
                    {field: 'user_name', title: '管理员名称'},
                    {field: 'mobile', title: '手机号'},
                    {field: 'email', title: '邮箱'},
                    {
                        field: 'operate',
                        title: '操作',
                        table: table,
                        events: Table.api.events.operate,
                        formatter: Table.api.formatter.operate
                    }],
            })
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        recyclebin: function () {
            var table = $("#table");
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    recyclebin_url: '/auth/admin/recycleBin',
                }
            });
            $(table).bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.recyclebin_url,
                columns: [
                    {checkbox: true,},
                    {field: 'id', title: 'ID',},
                    {field: 'user_name', title: '用户名',},
                    {field: 'delete_time', title: '删除时间'},
                    {
                        field: 'operate',
                        title: '操作',
                        table: table,
                        events: Table.api.events.operate,
                        formatter: Table.api.formatter.operate,
                        buttons: [
                            {
                                name: 'Restore',
                                text: '还原',
                                classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                icon: 'fa fa-rotate-left',
                                url: '/auth/admin/restore',
                                confirm: '是否确定还原该项',
                                refresh: true
                            },
                            {
                                name: 'Destroy',
                                text: '彻底删除',
                                classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                icon: 'fa fa-times',
                                url: '/auth/admin/destroy',
                                confirm: '是否确定彻底删除该项',
                                refresh: true
                            }
                        ],
                    }],
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        events: {},
        api: {
            bindevent: function () {
                var form = $('form[role="form"]');
                Form.api.bindevent(form);
            }
        }

    };
    return Controller;
});
